﻿Imports System.Reflection
Imports System.Text.RegularExpressions

Namespace bl.bo
    Public Class regExRule
        Inherits Rule

        Private _regex As String

        Public Sub New(ByVal propertyName As String, ByVal description As String, ByVal regex As String)
            MyBase.New(propertyName, description)
            _regex = regex
        End Sub

        Public Overrides Function validateRule(ByRef businessObject As genericBusinessObject) As Boolean
            Dim pi As PropertyInfo = businessObject.GetType.GetProperty(Me.propertyName)
            Dim m As Match = Regex.Match(pi.GetValue(businessObject, Nothing).ToString, _regex)
            If m.Success Then
                Return True
            Else
                Return False
            End If
        End Function
    End Class
End Namespace

